﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

namespace XnaCanvas {
    public class XTrigger {
        internal void SetMouseLocation(System.Windows.Point point) {
            this.mouseLocatoin = new Vector2((float)point.X,(float)point.Y);
            if (this.MouseLocationState!=null) {
                this.MouseLocationState(this);
            }
        }
        private bool isMouseRightButtonDown;
        public bool IsMouseRightButtonDown {
            get { return isMouseRightButtonDown; }
            internal set {
                if (this.MouseRightButtonState != null && isMouseRightButtonDown != value) {
                    this.MouseRightButtonState(this);
                }
                isMouseRightButtonDown = value;
            }
        }
        private bool isMouseLeftButtonDown;
        public bool IsMouseLeftButtonDown {
            get { return isMouseLeftButtonDown; }
            internal set {
                if (this.MouseLeftButtonState != null && isMouseLeftButtonDown != value) {
                    this.MouseLeftButtonState(this);
                }
                isMouseLeftButtonDown = value;
            }
        }
        bool isMouseEnter;

        public bool IsMouseEnter {
            get { return isMouseEnter; }
            set {
                if (this.MouseEnterState != null && isMouseEnter != value) {
                    this.MouseEnterState(this);
                }
                isMouseEnter = value;
            }
        }
        private bool isKeyDown;

        public bool IsKeyDown {
            get { return isKeyDown; }
            internal set {
                if (this.KeyState != null && this.isKeyDown != value) {
                    this.KeyState(this);
                }
                isKeyDown = value;
            }
        }
        private Key currentKey;

        public Key CurrentKey {
            get { return currentKey; }
            internal set { currentKey = value; }
        }
        private Microsoft.Xna.Framework.Vector2 mouseLocatoin;
        System.Windows.Point xpoint;
        public System.Windows.Point MouseLocatoin {
            get { xpoint.X = mouseLocatoin.X; xpoint.Y = mouseLocatoin.Y; return xpoint; }
        }

        private TimeSpan deltaTime;

        public TimeSpan DeltaTime {
            get { return deltaTime; }
            internal set {
                if (this.FrameRefresh!=null) {
                    this.FrameRefresh(this);
                }
                deltaTime = value; }
        }
        private TimeSpan totalTime;

        public TimeSpan TotalTime {
            get { return totalTime; }
            internal set { totalTime = value; }
        }
        /// <summary>
        /// current sence number
        /// </summary>
        private int csn;

        public int Csn {
            get { return csn; }
            internal set { csn = value; }
        }
        private int mouseClickCount;

        public int MouseClickCount {
            get { return mouseClickCount; }
            internal set { mouseClickCount = value; }
        }
        private int keyClickCount;

        public int KeyClickCount {
            get { return keyClickCount; }
            internal set { keyClickCount = value; }
        }
        public XCanvas Parent { get; private set; }
        internal XTrigger(XCanvas xc) {
            this.Parent = xc;
        }

        internal RasterizerState rs = new RasterizerState();
         public RasterizerState Rs {
             get { return rs; }
             set { rs = value; }
         }
        #region events
        public event TriggerEventHandler KeyState;
        public event TriggerEventHandler MouseLeftButtonState;
        public event TriggerEventHandler MouseRightButtonState;
        public event TriggerEventHandler MouseEnterState;
        public event TriggerEventHandler MouseLocationState;
        public event TriggerEventHandler FrameRefresh;
        #endregion        
    }
    public delegate void TriggerEventHandler(XTrigger sender);
}
